import os
import configparser
from common.consts import CONFIG_PATH


class Config(object):

    def __init__(self, filename="config.ini"):
        self.cf = configparser.ConfigParser()
        self.log_path = os.path.join(CONFIG_PATH, filename)
        self.cf.read(self.log_path)

    def get_conf(self, section, option):
        return self.cf.get(section, option)

    def set_conf(self, section, option, value):
        self.cf.set(section, option, value)
        with open(self.log_path, "w+") as f:
            return self.cf.write(f)

    def add_section(self, section):
        self.cf.add_section(section)
        with open(self.log_path, "w+") as f:
            return self.cf.write(f)

    def get_runtime(self, option):
        return self.get_conf("runtime", option)

    def get_server(self, option):
        return self.get_conf("server", option)

    def get_db_test(self, option):
        return self.get_conf("db_test", option)

    def get_email(self, option):
        return self.get_conf("email", option)

    def get_admin(self, option):
        return self.get_conf("admin_info", option)
